package com.cskaoyan.controller.goodsController;

import com.cskaoyan.model.bean.Comment;
import com.cskaoyan.model.bean.Region;
import com.cskaoyan.model.bean.Topic;
import com.cskaoyan.model.bo.goods.CommentBo;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.goods.wxVo.*;
import com.cskaoyan.service.goods.WxGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
public class WxGoodsController {

    @Autowired
    WxGoodsService wxGoodsService;

    @RequestMapping("wx/goods/count")
    public BaseRespVo goodsCount() {

        int count = wxGoodsService.goodsCount();
        CountVo countVo = new CountVo();
        countVo.setGoodsCount(count);
        return  BaseRespVo.ok(countVo);
    }

    @RequestMapping("wx/goods/category")
    public BaseRespVo goodsCategory(Integer id) {
        CategoryVo categoryVo = wxGoodsService.goodsListByCatgory(id);



        return BaseRespVo.ok(categoryVo);
    }


    @RequestMapping(value="wx/goods/list" ,params = {"categoryId","page", "size"})
    public BaseRespVo goodsLists(Integer categoryId, Integer page, Integer size) {
        GoodsListVo goodsListVo = wxGoodsService.goodsLists(categoryId, page, size);


        return BaseRespVo.ok(goodsListVo);
    }

    @RequestMapping("wx/goods/detail")
    public BaseRespVo goodsDetail(Integer id) {
        GoodsDetailVo goodsDetailVo = wxGoodsService.goodsDetail(id);
        return BaseRespVo.ok(goodsDetailVo);
    }

    @RequestMapping("wx/goods/related")
    public BaseRespVo goodsRelate(Integer id) {

        RelateGoodsVo relateGoodsVo = wxGoodsService.goodsRelated(id);

        return BaseRespVo.ok(relateGoodsVo);


    }
   // TODO 推荐重新做

    @RequestMapping("wx/topic/detail")
    public BaseRespVo topicDetail(Integer id) {

        TopicDetalVo topicDetalVo = wxGoodsService.topicDetail(id);

        return  BaseRespVo.ok(topicDetalVo);
    }

    @RequestMapping("wx/topic/related")
    public BaseRespVo topicRelated(Integer id) {
        List<Topic> topics = wxGoodsService.topicRealted(id);
        return BaseRespVo.ok(topics);
    }


    // TODO detail重新做

    @RequestMapping("wx/comment/count")
    public BaseRespVo commentCount(Integer valueId,Byte type) {

        CountCommentVo countCommentVo = wxGoodsService.commentCount(valueId, type);

        return BaseRespVo.ok(countCommentVo);
    }

    @RequestMapping("wx/comment/list")
    public BaseRespVo commentLists(Integer valueId, Byte type, Integer size, Integer page, Byte showType) {
        CommentListVo commentListVo = wxGoodsService.comentLists(valueId, type, size, page, showType);
        return BaseRespVo.ok(commentListVo);
    }

    @RequestMapping("wx/topic/list")
    public BaseRespVo topicLists(Integer page, Integer size) {
        TopicListsVo topicListsVo = wxGoodsService.topicLists(page, size);


        return BaseRespVo.ok(topicListsVo);

    }

    @RequestMapping("wx/region/list")
    public BaseRespVo regionLists(Integer pid) {

        List<Region> regions = wxGoodsService.regionLists(pid);
        return BaseRespVo.ok(regions);


    }

    @RequestMapping("wx/comment/post")
    public BaseRespVo commentAdd(@RequestBody CommentBo commentBo) {
        Comment comment = wxGoodsService.commentAdd(commentBo);
        return BaseRespVo.ok(comment);
    }








}
